package com.example.helloandroid;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {
	
	private VideoView mVideoView;
	
	private static final String VIDEO_PATH = Environment
			.getExternalStorageDirectory() + File.separator + "yang.mp4";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Log.d("leochin", "onCreate");

		if (mVideoView == null) {
			mVideoView = (VideoView) this.findViewById(R.id.main_videoview);
			MediaController controller = new MediaController(this);
			mVideoView.setMediaController(controller);
			mVideoView.setVideoPath(VIDEO_PATH);
			mVideoView.requestFocus();
		}

		if (savedInstanceState != null
				&& savedInstanceState.getInt("currentposition") != 0) {

			mVideoView.seekTo(savedInstanceState.getInt("currentposition"));
		}
		mVideoView.start();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();	
		Log.d("leochin", "onDestroy");
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub		
		super.onPause();
		Log.d("leochin", "onPause");
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub		
		super.onRestart();
		Log.d("leochin", "onRestart");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub		
		super.onResume();
		Log.d("leochin", "onResume");
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub	
		super.onStart();
		Log.d("leochin", "onStart");
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub	
		super.onStop();
		Log.d("leochin", "onStop");
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		// TODO Auto-generated method stub	
		super.onRestoreInstanceState(savedInstanceState);
		Log.d("leochin", "onRestoreInstanceState");
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub		
		super.onSaveInstanceState(outState);
				
		outState.putInt("currentposition", mVideoView.getCurrentPosition());	
		Log.d("leochin", "onSaveInstanceState");
	}
}
